package com.tangtang.core.log;

import java.net.URL;

import org.apache.log4j.*;

import com.tangtang.core.ClassLoaderUtil;

public class LogUtil {
    static Logger _logger;

    static {
        try {
            URL url = ClassLoaderUtil.getExtendResource("log4j.properties");
            if (url != null) {
                PropertyConfigurator.configure(url);
                _logger = LogManager.getRootLogger();
            } else {
                _logger = LogManager.getRootLogger();
                PatternLayout layout = new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN);
                ConsoleAppender consoleAppender = new ConsoleAppender(layout);
                _logger.addAppender(consoleAppender);
                DailyRollingFileAppender drfAppender = new DailyRollingFileAppender(layout, "log.txt", "'.'yyyy-MM-dd");
                _logger.addAppender(drfAppender);
            }
        } catch (Exception ex) {

        }
    }

    public static void debug(Object message) {
        _logger.debug(message);
    }

    public static void debug(Object message, Throwable t) {
        _logger.debug(message, t);
    }

    public static void warn(Object message) {
        _logger.warn(message);
    }

    public static void warn(Object message, Throwable t) {
        _logger.warn(message, t);
    }

    public static void info(Object message) {
        _logger.info(message);
    }

    public static void info(Object message, Throwable t) {
        _logger.info(message, t);
    }

    public static void error(Object message) {
        _logger.error(message);
    }

    public static void error(Object message, Throwable t) {
        _logger.error(message, t);
    }

    public static void fatal(Object message) {
        _logger.fatal(message);
    }

    public static void fatal(Object message, Throwable t) {
        _logger.fatal(message, t);
    }
}
